package com.web.mall.service.impl;

import com.web.mall.mapper.TbBrandMapper;
import com.web.mall.pojo.TbBrand;
import com.web.mall.service.BrandManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service
public class BrandManagerServiceImpl implements BrandManagerService {

    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public List<TbBrand> queryBrand() {
        return tbBrandMapper.selectByExample(null);
    }

    @Override
    public TbBrand findNewsById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean saveBrand(TbBrand brand) {
        //判断 brand id
        if(ObjectUtils.isEmpty(brand.getId())){
            tbBrandMapper.insert(brand);
        }else {
            tbBrandMapper.updateByPrimaryKey(brand);
        }
        return true;
    }

    @Override
    public boolean deleteBrand(Long id) {
        if(id!=null){
            tbBrandMapper.deleteByPrimaryKey(id);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<TbBrand> findBrandList() {
        return tbBrandMapper.selectByExample(null);
    }
}
